// Movie.h: interface for the Movie class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_MOVIE_H__E7518254_C08A_4D34_9C8F_8ACF2455BADD__INCLUDED_)
#define AFX_MOVIE_H__E7518254_C08A_4D34_9C8F_8ACF2455BADD__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <stdio.h>
#include <plib/ul.h>
#include <plib/sg.h>
#include <plib/ssg.h>

#define CAMERA_SELECTED_MODEL_NAME "./cameraSelected.ac"
#define CAMERA_NORMAL_MODEL_NAME "./cameraNormal.ac"

#define LINE_BLUE	0.1f,0.4f,0.9f,0.6f

#define MOVIE_LINE_HEIGTH 5.0f

#define MOVIE_MIN_HEIGTH 10.0f

#define MOVIE_SELECTED_MASK 0x2 
#define MOVIE_NORMAL_MASK   0x1

#define MOVIE_SELECTED 1 
#define MOVIE_NORMAL   0

#define CAMERA 0
#define TRACK  1

#define MOVIE_SPEED 150.0f // m/sec
 
struct Frame
{
	float e;
	float n;
	float z;   // heigth of terrain
	float a;   // height over terrain
	float az;  // a + z
	float h;
	float p;
	float r;
	bool selected;
	ssgSelector* cameraModel;
	ssgTransform* cameraTransform;
	ssgTransform* lineTransform;
};

class Movie  
{
public:
	Movie(char filename[], float xc, float yc);
	virtual ~Movie();

	void create(ssgRoot* root);
	void add(ssgRoot* root, float x, float y, float z);
	void remove(Frame *fr);
	void insert(ssgRoot* root, int bp, int ap, float x, float y, float z);
	void fprint(FILE* f);
	Frame* get(ssgTransform* t);
	Frame* get(ssgTransform* t, int what);
	int getPosition(Frame* fr);
	void reposition(ssgRoot* root, Frame *fr, float x, float y, float z);
	sgCoord* getLERPCameraPosition();

	// enter/exit movie mode
	void start();
	void end();

	// movie controls
	void play();
	void update();
	void stop();
	void next();
	void before();
	void forward();
	void rewind();

private:
	ssgEntity*    cameraSelectedModel;
	ssgEntity*    cameraNormalModel;
	ssgTransform* filmTrack;

	float getHeigth(float x, float y, ssgRoot* r);
	ssgTransform* createLine(ssgTransform* t, Frame* w1, Frame* w2);
	void LERPframes(float dt);

	float x_correction;
	float y_correction;

	ulLinkedList* movieList;

	ulClock *ck;

	int playingFrameNumber;
	int nextFrameNumber;

	bool playing;

	float distance;

	sgCoord currentCameraPosition;

	bool lastFrameReached;
};

#endif // !defined(AFX_MOVIE_H__E7518254_C08A_4D34_9C8F_8ACF2455BADD__INCLUDED_)
